package dev.alm.javaproject.utils;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

public class Utils {

    private static String secret = "abcdefghijklmnopqrstuvwxyz";

    // TODO
    // 雪花算法生成id

    // 生成JWT token
    public static String generateJwtToken(String username) {
        return Jwts.builder().setHeaderParam("type","JWT").setSubject(username).signWith(SignatureAlgorithm.HS256, secret).compact();
    }

    // 解析token
    public static String parseJwtToken(String token) {
        return Jwts.parser().setSigningKey(secret).parseClaimsJws(token).getBody().getSubject();
    }

}
